import api from '../../utils/api';

Page({
  data: {
    classInfo: null,
    isTeacher: false
  },

  onLoad(options) {
    this.fetchClassInfo(options.id);
  },

  async fetchClassInfo(classId) {
    try {
      const classInfo = await api.getClassInfo(classId);
      this.setData({
        classInfo,
        isTeacher: classInfo.role === 'teacher'
      });
    } catch (error) {
      wx.showToast({
        title: error.message || '获取班级信息失败',
        icon: 'none'
      });
    }
  },

  // 显示班级码（仅老师可见）
  showClassCode() {
    if (!this.data.isTeacher) return;
    
    wx.showModal({
      title: '班级码',
      content: this.data.classInfo.class_code,
      showCancel: false
    });
  }
});